package com.dengdai.applibrary.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * @说明 Adapter基本类
 * @作者 LY
 * @时间 15/12/21 14:29
 * @版权 Copyright(c) 2015 LY-版权所有
 */
public class BaseCommAdapter<T> extends BaseAdapter {
    protected List<T> listData = new ArrayList<T>();
    protected Context mContext;
    protected LayoutInflater inflater;

    public BaseCommAdapter(Context context) {
        this.mContext = context;
        this.inflater = LayoutInflater.from(context);
    }

    /**
     * 设置数据
     *
     * @param listData
     */
    public void setList(List<T> listData) {
        if (listData != null && listData.size() > 0) {
            this.listData.addAll(listData);
        }
        notifyDataSetChanged();
    }

    /**
     * 添加数据
     *
     * @param alObjects
     */
    public void addObject(T alObjects) {
        if (null != alObjects) {
            this.listData.add(alObjects);
            notifyDataSetChanged();
        }
    }

    /**
     * 清理数据
     */
    public void clear() {
        this.listData.clear();
        notifyDataSetChanged();
    }

    /**
     * 删除一个
     *
     * @param position
     */
    public void removeItem(int position) {
        this.listData.remove(position);
        notifyDataSetChanged();
    }

    public List<T> getListData() {
        return listData;
    }

    public void setListData(List<T> listData) {
        this.listData = listData;
    }

    @Override
    public int getCount() {
        return listData == null ? 0 : listData.size();
    }

    @Override
    public Object getItem(int position) {
        return listData == null ? null : listData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return listData == null ? 0 : position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return null;
    }
}
